package fengstyle;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@RefreshScope
@RestController
@EnableDiscoveryClient
@SpringBootApplication
public class NacosDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosDemoApplication.class, args);
    }

    @Value("${user.name}")
    private String name;

    @Value("${user.age}")
    private Integer age;

    @PostConstruct
    public void init(){
        System.out.printf("[init] user name : %s, user age : %d%n", name, age);
    }

    @GetMapping("/user")
    public String user(){
        return String.format("[/user] user name : %s, user age : %d", name, age);
    }

}
